package com.harry.decoupling.impl.proxy;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;

import com.harry.basis.BaseGeneric;
import com.harry.basis.BasePoEntity;
import com.harry.decoupling.defi.module.RestfulMgr;
import com.harry.decoupling.defi.proxy.RestfulMgrProxy;

@Component
public class RestfulProxyImplMgr implements RestfulMgrProxy {

	@Override
	public <T extends BasePoEntity> void getone(Class<T> entityClass, Map<String, Object> params, HttpServletRequest request, HttpServletResponse response, Map<String, Object> data) throws Exception {
		impl(entityClass).getone(params, request, response, data);
	}

	@Override
	public <T extends BasePoEntity> void getlist(Class<T> entityClass, Map<String, Object> params, HttpServletRequest request, HttpServletResponse response, Map<String, Object> data) throws Exception {
		impl(entityClass).getlist(params, request, response, data);
	}

	@Override
	public <T extends BasePoEntity> void post(Class<T> entityClass, Map<String, Object> params, HttpServletRequest request, HttpServletResponse response, Map<String, Object> data) throws Exception {
		impl(entityClass).post(params, request, response, data);
	}

	@Override
	public <T extends BasePoEntity> void patch(Class<T> entityClass, Map<String, Object> params, HttpServletRequest request, HttpServletResponse response, Map<String, Object> data) throws Exception {
		impl(entityClass).patch(params, request, response, data);
	}

	@Override
	public <T extends BasePoEntity> void delete(Class<T> entityClass, Map<String, Object> params, HttpServletRequest request, HttpServletResponse response, Map<String, Object> data) throws Exception {
		impl(entityClass).delete(params, request, response, data);
	}

	@Override
	public <T extends BasePoEntity> void getexcel(Class<T> entityClass, Map<String, Object> params, HttpServletRequest request, HttpServletResponse response, Map<String, Object> data) throws Exception {
		impl(entityClass).getexcel(params, request, response, data);
	}

	@Override
	public <T extends BasePoEntity> void exists(Class<T> entityClass, Map<String, Object> params, HttpServletRequest request, HttpServletResponse response, Map<String, Object> data) throws Exception {
		impl(entityClass).exists(params, request, response, data);
	}

	@SuppressWarnings("unchecked")
	private <T extends BasePoEntity> RestfulMgr<T> impl(Class<T> entityClass) throws Exception {
		return (RestfulMgr<T>) BaseGeneric.beanOf(RestfulMgr.class, entityClass);
	}
}
